<template>
	<view class="payPage" v-if="coursesBuyDetail">
		<view class="points">
			<view class="remaining">
				剩余积分：<view class="num">{{coursesBuyDetail.sum_score}}</view>
			</view>
			<view class="white">
				<view class="">
					<view class="num">{{coursesBuyDetail.fixed_score}}</view>
					<view>固定积分</view>
				</view>
				<view class="">
					<view class="num">{{coursesBuyDetail.score}}</view>
					<view>自由积分</view>
				</view>
			</view>
		</view>
		<view class="priceDetail">
			<view class="title">
				应付积分<view class="right">{{coursesBuyDetail.pay_money}}固定积分</view>
			</view>
			<view class="list">
				<view>创建时间</view>
				<view>{{coursesBuyDetail.createtime}}</view>
			</view>
			<view class="list">
				<view>订单号</view>
				<view>{{coursesBuyDetail.out_trade_no}}</view>
			</view>
		</view>
		<view class="sure" @click="orderConfirm">抵扣</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				courses_id: null,
				coupon_id: null,
				coursesBuyDetail: null,
			};
		},
		onLoad(options) {
			if (options && options.courses_id) {
				this.courses_id = options.courses_id
				this.coupon_id = options.coupon_id
				this.courseOrderScore();
			}
		},
		methods: {
			orderConfirm() {
				let that = this
				uni.showModal({
					title: "提示",
					content: "兑换此课程需要消耗" + this.coursesBuyDetail.pay_money + "积分，是否兑换?",
					success(res) {
						if (res.confirm) {
							that.$Api.courses.submitCourseOrder({
								pay_type: 2,
								course_id: that.courses_id,
								coupon_id: that.coupon_id,
								out_trade_no: that.coursesBuyDetail.out_trade_no
							}).then((res) => {
								that.$Tips({
									title: '兑换成功'
								}, {
									tab: 4,
									url: '/pages/common/exchangeSuccess'
								})
							});
						}
					}
				})
			},
			courseOrderScore() {
				this.$Api.courses.courseOrderScore({
					course_id: this.courses_id,
					coupon_id: this.coupon_id
				}).then((res) => {
					this.coursesBuyDetail = res.data
				});
			}

		},
	};
</script>

<style lang="scss" scoped>
	.payPage {
		height: 100%;
		min-height: 100vh;
		font-family: PingFang SC;
		background: #fff;
		padding: 0 32rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
		box-sizing: border-box;

		.points {
			width: 100%;
			height: 328rpx;
			background: linear-gradient(270deg, #ddf79a 0%, #a3c616 100%);
			box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1),
				inset 0rpx 2rpx 2rpx 0rpx #ffffff;
			border-radius: 28rpx;
			margin-top: 21rpx;
			padding: 30rpx 20rpx;
			box-sizing: border-box;

			.remaining {
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;

				.num {
					font-size: 48rpx;
				}
			}

			.white {
				width: 642rpx;
				height: 168rpx;
				background: linear-gradient(180deg, #E8FFED 0%, #FFFFFF 99%);
				box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1), inset 0rpx 2rpx 2rpx 0rpx #FFFFFF;
				border-radius: 28rpx;
				margin-top: 36rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;
				text-align: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;

				.num {
					font-weight: 500;
					font-size: 44rpx;
					color: #333333;
				}
			}
		}

		.priceDetail {
			width: 100%;
			background: #ffffff;

			margin-top: 20rpx;
			padding: 30rpx;
			box-sizing: border-box;

			.title {
				font-size: 28rpx;
				border-bottom: 1px #e6e5e5 solid;
				padding-bottom: 18rpx;
				display: flex;
				justify-content: space-between;

				.right {
					color: #fd463e;
					font-size: 34rpx;
				}
			}

			.u-radio-group--row {
				display: block;
			}

			.list {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 28rpx;
				margin-top: 26rpx;

				.name {
					display: flex;
					align-items: center;
				}

				.img {
					width: 52rpx;
					margin-right: 16rpx;
				}
			}
		}

		.sure {
			margin: 140rpx 30rpx 0;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			font-weight: bold;
			font-size: 34rpx;
			color: #ffffff;
			background: #a3c616;
			box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(163, 198, 22, 0.3);
			border-radius: 24rpx;
		}
	}
</style>